package avicit.im.lantop.basic.archiveRecommendFolder.rest;


import avicit.im.lantop.basic.archiveRecommendFolder.domain.ArchiveFolder;
import avicit.im.lantop.basic.archiveRecommendFolder.service.ArchiveRecommendFolderService;
import avicit.im.lantop.basic.archiveRecommendFolder.service.api.ArchiveRecommendFolderServiceApi;
import avicit.im.lantop.basic.fieldmapset.action.rest.LantopFieldMapSetServiceRest;
import avicit.platform6.core.context.ThreadContextHelper;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Map;

/**
 * @金航数码科技有限责任公司
 * @作者：jiam
 * @邮箱：jiam@avic-digital.com
 * @创建时间： 2020-12-31 14:52
 * @类说明：oa_travel_rbRest
 * @修改记录：
 */

@RestController
@Api(tags = "ArchiveRecommendFolderRest", description = "ArchiveRecommendFolderRest")
@RequestMapping("/api/avicit/im/lantop/basic/archiveRecommendFolder/rest/ArchiveRecommendFolderRest")
public class ArchiveRecommendFolderRest {


    private static final Logger LOGGER = LoggerFactory.getLogger(ArchiveRecommendFolderRest.class);


    @Autowired
    private ArchiveRecommendFolderService folderService;


    /**
     * 获取推荐文件夹表格数据
     * @param map
     * @return
     */
    @PostMapping("/getRecommendFolderDatagrid")
    @ApiOperation(value = "获取推荐文件夹表格数据")
    public ResponseMsg<Map<String, Object>> getRecommendFolderDatagrid(@ApiParam(value = "获取推荐文件夹表格数据", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<Map<String, Object>> responseMsg = new ResponseMsg<>();
        try {
            String orgId = (String) map.get("orgId");
            String sysId = (String) map.get("sysId");
            Integer page = (Integer) map.get("page");
            Integer rows = (Integer) map.get("rows");
            Map<String, Object> recommendFolderDatagrid = folderService.getRecommendFolderDatagrid(orgId, sysId, page, rows);
            responseMsg.setResponseBody(recommendFolderDatagrid);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 添加推荐文件夹
     * @param map
     * @return
     */
    @PostMapping("/saveRecommendFolder")
    @ApiOperation(value = "添加推荐文件夹")
    public ResponseMsg<Integer> saveRecommendFolder(@ApiParam(value = "添加推荐文件夹", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg<Integer> responseMsg = new ResponseMsg<>();
        try {
            ArchiveFolder folder = (ArchiveFolder) map.get("folder");
            Integer integer = folderService.saveRecommendFolder(folder);
            responseMsg.setResponseBody(integer);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 删除推荐文件夹
     * @param map
     * @return
     */
    @PostMapping("/deleteRecommendFolder")
    @ApiOperation(value = "删除推荐文件夹")
    public ResponseMsg deleteRecommendFolder(@ApiParam(value = "删除推荐文件夹", name = "map") @RequestBody Map<String,Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            String folderIds = (String) map.get("folderIds");
            folderService.deleteRecommendFolder(folderIds);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }
}
